package com.mldong;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;

import javax.annotation.Resource;

/**
 *
 * 基础测试类（JUnit5重构版）
 * @author mldong
 * @date 2022-01-06
 */
@ExtendWith(SpringExtension.class)
@SpringBootTest(classes = MldongAdminApplication.class)
@WebAppConfiguration
//@Transactional(rollbackFor = Exception.class) //打开的话测试之后数据可自动回滚
public class BaseJunit {

    @Resource
    private WebApplicationContext webApplicationContext;

    private MockMvc mockMvc;

    @BeforeEach
    public void setupMockMvc() {
        mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
    }

    @BeforeEach
    public void initDatabase() {
        // 可以在这里添加数据库初始化逻辑
    }
}
